using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Paxman.Screens;
using Paxman.Misc;

namespace Paxman
{
    /// <summary>
    /// GameMain
    /// </summary>
    public class Game : Microsoft.Xna.Framework.Game
    {
        enum Screens { Intro, Level };

        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        Screens currentScreen;

        Level level;

        public Game()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            graphics.PreferredBackBufferWidth = 770;
            graphics.PreferredBackBufferHeight = 600;
            Window.Title = "Paxman 0.1";
            IsMouseVisible = false;
            //graphics.ToggleFullScreen();
            graphics.ApplyChanges();

            Util.windowWidth = Window.ClientBounds.Width;
            Util.windowHeight = Window.ClientBounds.Height;

            currentScreen = Screens.Level;
        }

        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            level = new Level();
            level.LoadContent(Content);
            level.StartFirstLevel();
        }

        protected override void UnloadContent()
        {
        }

        protected override void Update(GameTime gameTime)
        {
            Controls.SetOldState();
            Controls.GetState();

            if (Controls.IsKeyDownOnce(Keys.Escape))
                this.Exit();

            switch (currentScreen)
            {
                case Screens.Intro:
                    break;
                case Screens.Level:
                    level.Update(gameTime);
                    break;
            }

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            spriteBatch.Begin();
            switch (currentScreen)
            {
                case Screens.Intro:
                    break;
                case Screens.Level:
                    level.Draw(gameTime, spriteBatch);
                    break;
            }
            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}
